﻿<UserControl x:Class="TfsWorkbench.HierarchyUI.HierarchyObjects.HierarchyItemNode"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:UIElements="clr-namespace:TfsWorkbench.UIElements;assembly=TfsWorkbench.UIElements" 
             xmlns:HierarchyUI="clr-namespace:TfsWorkbench.HierarchyUI" 
             xmlns:Conterters="clr-namespace:TfsWorkbench.HierarchyUI.Conterters" 
             xmlns:ValueConverters="clr-namespace:TfsWorkbench.UIElements.ValueConverters;assembly=TfsWorkbench.UIElements" 
             mc:Ignorable="d" 
             d:DesignHeight="100" 
             d:DesignWidth="150"
             Name="PART_ControlBase"
             Cursor="{x:Static UIElements:CustomCursors.Hand}"
             MouseDoubleClick="HierarchyItemNode_OnMouseDoubleClick"
             >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/TfsWorkbench.UIElements;Component/Resources/CommandButtonStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <Conterters:StateColourConverter x:Key="StateColourConverter" />
            <ValueConverters:CaptionConverter x:Key="CaptionConverter" />
            <ValueConverters:OwnerConverter x:Key="OwnerConverter" />
            <ValueConverters:NumericConverter x:Key="NumericConverter" />
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid DataContext="{Binding ElementName=PART_ControlBase, Path=HierarchItem}">
        <Grid.ToolTip>
            <UIElements:WorkbenchItemToolTip WorkbenchItem="{Binding Path=WorkbenchItem}" />
        </Grid.ToolTip>
        <Grid.ContextMenu>
            <UIElements:WorkbenchItemContextMenu
                WorkbenchItem="{Binding WorkbenchItem}"
                >
                <MenuItem
    				CommandParameter="{Binding WorkbenchItem}" 
    				Command="{x:Static UIElements:CommandLibrary.EditItemCommand}"
    				CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                    TextBlock.FontWeight="Bold"
                    >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource EditIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                    <MenuItem.Header>
                        <TextBlock>
					        <TextBlock.Text>
					            <MultiBinding StringFormat="{}Edit ({0}) {1}">
							        <Binding Path="WorkbenchItem[System.Id]" />
							        <Binding Path="WorkbenchItem[System.WorkItemType]"/>
						        </MultiBinding>
					        </TextBlock.Text>
                        </TextBlock>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem 
    				Header="Filter To Children"
    				CommandParameter="{Binding WorkbenchItem}" 
    				Command="{x:Static HierarchyUI:LocalCommandLibrary.FilterToItemCommand}"
    				CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                    >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource FilterIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem 
    				Header="Open In Browser"
    				CommandParameter="{Binding WorkbenchItem}" 
    				Command="{x:Static UIElements:CommandLibrary.OpenItemInBrowserCommand}"
    				CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                    >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource WebIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem 
    				Header="Save Changes"
    				CommandParameter="{Binding WorkbenchItem}" 
    				Command="{x:Static UIElements:CommandLibrary.SaveItemCommand}"
    				CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                    >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource SaveIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem 
    				Header="Refresh / Reset"
    				CommandParameter="{Binding WorkbenchItem}" 
    				Command="{x:Static UIElements:CommandLibrary.RefreshItemCommand}"
    				CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                    >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource RefreshIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem 
    				Header="Discard Unsaved Item"
    				CommandParameter="{Binding WorkbenchItem}" 
    				Command="{x:Static UIElements:CommandLibrary.DiscardItemCommand}"
    				CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                    >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource DeleteIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                </MenuItem>
            </UIElements:WorkbenchItemContextMenu>
        </Grid.ContextMenu>
        <Rectangle
            RadiusX="5"
            RadiusY="5"
            Fill="White"
            />
        <Rectangle
            RadiusX="5"
            RadiusY="5"
            Opacity="0.55"
            >
            <Rectangle.Fill>
                <MultiBinding Converter="{StaticResource StateColourConverter}">
                    <MultiBinding.Bindings>
                        <Binding Path="WorkbenchItem[System.State]" />
                        <Binding Path="ParentViewMap" />
                    </MultiBinding.Bindings>
                </MultiBinding>
            </Rectangle.Fill>
        </Rectangle>
        <Border
            BorderBrush="Black"
            BorderThickness="1"
            CornerRadius="5"
            >
            <DockPanel Margin="4,4,4,23">
                <TextBlock FontWeight="Bold" TextTrimming="CharacterEllipsis" DockPanel.Dock="Top">
					<TextBlock.Text>
					    <MultiBinding StringFormat="{}({0}) {1}">
							<Binding Path="WorkbenchItem[System.Id]" />
							<Binding Path="WorkbenchItem[System.WorkItemType]"/>
						</MultiBinding>
					</TextBlock.Text>
                </TextBlock>
                <TextBlock 
                    DockPanel.Dock="Bottom" 
                    TextTrimming="CharacterEllipsis"
                    HorizontalAlignment="Right"
                    FontStyle="Italic">
                    <TextBlock.Text>
                        <MultiBinding Converter="{StaticResource OwnerConverter}">
                            <Binding Path="WorkbenchItem[System.State]" />
                            <Binding Path="WorkbenchItem" />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
                <TextBlock 
                    DockPanel.Dock="Top" 
                    TextWrapping="Wrap" 
                    TextTrimming="CharacterEllipsis">
                    <TextBlock.Text>
                        <MultiBinding Converter="{StaticResource CaptionConverter}">
                            <Binding Path="WorkbenchItem[System.State]" />
                            <Binding Path="WorkbenchItem" />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
            </DockPanel>
        </Border>
        <DockPanel VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="25">
            <Button
                CommandParameter="{Binding WorkbenchItem}" 
    		    Command="{x:Static UIElements:CommandLibrary.SaveItemCommand}"
    		    CommandTarget="{Binding ElementName=PART_ControlBase}"
                Width="25"
                ToolTip="Save"
                Style="{StaticResource SaveButtonStyle}" Margin="0,0,1,0"
                DockPanel.Dock="Right"
                />
            <TextBlock 
                Margin="4,0,2,4"
                DockPanel.Dock="Right" 
                TextTrimming="CharacterEllipsis"
                VerticalAlignment="Bottom"
                FontWeight="Bold"
                FontSize="16"
                >
                <TextBlock.Text>
                    <MultiBinding Converter="{StaticResource NumericConverter}">
                        <Binding Path="WorkbenchItem[System.State]" />
                        <Binding Path="WorkbenchItem" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <TextBlock 
                Margin="5,0,0,4"
                Text="{Binding Path=WorkbenchItem[System.State]}" 
                DockPanel.Dock="Left" 
                TextTrimming="CharacterEllipsis"
                VerticalAlignment="Bottom"
                MinWidth="50"
                />
        </DockPanel>
    </Grid>
</UserControl>
